<template>
  <view class="bg-white">
    <view class="bg-white solid-bottom">
      <uni-search-bar @confirm="search" :focus="true" v-model="searchValue"  @input="input">
      </uni-search-bar>
    </view>
    <scroll-view :scroll-top="scrollTop" scroll-y="true" class="scroll-Y"
                 @scrolltolower="lower" >
      <view v-for="item in wikiList" @click="onClick(item)">
        <uni-section :title="item.name" class="padding-xs" type="line" >
          <uni-card :cover="cover" >
           <image slot='cover' style="width: 100%;" :src="item.imageUrl"></image>
            <text class="uni-body">{{item.description}}</text>
            <view slot="actions" class="card-actions">
              <view class="card-actions-item margin-bottom-xs">
                <text class="card-actions-item-text">发布时间 {{item.creteTime}}</text>
              </view>
            </view>
          </uni-card>
        </uni-section>
      </view>

    </scroll-view>
  </view>
</template>

<script>

import {getWikiList} from "../../../api/flower/wiki";

export default {
  components: {},
  data() {
    return {
      cover: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao.jpg',
      avatar: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png',
      extraIcon:{
        color: '#4cd964',
        size: '22',
        type: 'gear-filled'
      },
      scrollTop: 0,
      searchValue:"",
      wikiList:[]
    }
  },
  //挂载的生命周期
  mounted() {
    this.getList()
  },
  methods: {
    onClick(item){
      console.log(item)
      if (item){
        //路由跳转的时候传参数
        //navigateTo 跳转传参数
        console.log(item);
        //拿到id 传给详情页
        let wikiId = item.id;
        //wikiId缓存起来
        uni.setStorageSync('wikiId',wikiId)

        uni.navigateTo(
            {
              url: '/pages/flower/wiki/wikiDetail',
              success: function(res) {
                console.log(res)
              },
              fail: function(res) {
                console.log(res)
              }
            }
        )
      }
    },
    //获取列表的信息
    getList(){
      let that = this;
      getWikiList({
        pageNum:1,
        pageSize:100,
        searchValue:this.searchValue
      }).then(res=>{
        console.log(res);
        that.wikiList = res.rows
      })
    },


    actionsClick(text){
      uni.showToast({
        title:text,
        icon:'none'
      })
    },

    lower: function(e) {
      console.log(e)
    },

    search(res) {
      uni.showToast({
        title: '搜索：' + res.value,
        icon: 'none'
      });
      this.getList()
    },
    input(res) {
      console.log('----input:', res)
    },

  }
}
</script>

<style lang="less" scoped>
.scroll-Y {
  height: calc(100vh - 100px);
}

</style>